import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router);

/* Layout */
const Layout = resolve => require(['@/views/layout/Layout'], resolve);
const LayoutColumn = resolve => require(['../components/AppColumn/index'], resolve);
import {Service} from 'vue-element-simple';
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  {path: '/login', component: resolve => require(['@/views/login/index'], resolve), hidden: true},
  {path: '/404', component: resolve => require(['@/views/404'], resolve), hidden: true},
  {
    path: '/',
    redirect: '/workbench'
  },

  {
    path: '/workbench',
    component: Layout,
    redirect: '/workbench/index',
    name: 'Workbench',
    meta: {title: '工作台', icon: '工作台', power: 'admin.workbench'},
    // alwaysShow: true,
    children: [
      {
        path: 'index',
        name: 'WorkbenchIndex',
        component: resolve => require(['@/views/workbench/index'], resolve),
        meta: {title: '概览', icon: '概览', power: 'admin.workbench.index'}
      }, {
        path: 'statistics',
        name: 'WorkbenchStatistics',
        component: resolve => require(['@/views/workbench/statistics'], resolve),
        meta: {title: '统计', icon: '统计', power: 'admin.workbench.statistics'}
      }
    ],
    noCache: false
  },

  {
    path: '/homepage',
    component: Layout,
    redirect: '/homepage/style',
    name: 'Homepage',
    meta: {title: '首页管理', icon: '首页管理', power: 'admin.homepage'},
    children: [
      {
        path: 'style',
        name: 'Style',
        component: resolve => require(['@/views/homepage/style/index'], resolve),
        meta: {title: '标题栏管理', icon: '标题栏管理', power: 'admin.homepage.style'}
      }, {
        path: 'banner',
        name: 'Banner',
        redirect: '/homepage/banner/list',
        component: LayoutColumn,
        meta: {title: '轮播图管理', icon: '轮播图管理', power: 'admin.homepage.banner'},
        children: [
          {
            path: 'list',
            name: 'HomepageBannerList',
            component: resolve => require(['@/views/homepage/banner/list'], resolve),
            meta: {title: '轮播图列表', power: 'admin.homepage.banner.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'HomepageBannerAdd',
            component: resolve => require(['@/views/homepage/banner/add'], resolve),
            meta: {title: '添加图片', power: 'admin.homepage.banner.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'HomepageBannerEdit',
            component: resolve => require(['@/views/homepage/banner/edit'], resolve),
            meta: {title: '编辑图片', power: 'admin.homepage.banner.edit'},
            hidden: true
          }]
      }, {
        path: 'models',
        name: 'Models',
        redirect: '/homepage/models/list',
        component: LayoutColumn,
        meta: {title: '导航栏管理', icon: '导航栏管理', power: 'admin.homepage.models'},
        children: [
          {
            path: 'list',
            name: 'HomepageModelsList',
            component: resolve => require(['@/views/homepage/models/list'], resolve),
            meta: {title: '导航栏列表', power: 'admin.homepage.models.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'HomepageModelsAdd',
            component: resolve => require(['@/views/homepage/models/add'], resolve),
            meta: {title: '添加导航项', power: 'admin.homepage.models.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'HomepageModelsEdit',
            component: resolve => require(['@/views/homepage/models/edit'], resolve),
            meta: {title: '编辑导航项', power: 'admin.homepage.models.edit'},
            hidden: true
          }]
        // }, {
        //   path: 'slogan',
        //   name: 'Slogan',
        //   component: resolve => require(['@/views/homepage/slogan/index'], resolve),
        //   meta: {title: '宣传语设置', icon: 'table', power: 'admin.homepage.slogan'}
      }, {
        path: 'plugin',
        name: 'PluginManage',
        component: resolve => require(['@/views/homepage/plugin/index'], resolve),
        meta: {title: '功能管理', icon: '功能管理', power: 'admin.homepage.slogan'}
      }
    ],
    noCache: false
  },

  {
    path: '/route',
    component: Layout,
    redirect: '/route/daily',
    name: 'Route',
    meta: {title: '路线管理', icon: '路线管理', power: 'admin.route'},
    children: [
      {
        path: 'daily',
        name: 'RouteDaily',
        redirect: '/route/daily/list',
        component: LayoutColumn,
        meta: {title: '巴士路线', icon: '巴士路线', power: 'admin.route.daily'},
        children: [
          {
            path: 'list',
            name: 'RouteDailyList',
            component: resolve => require(['@/views/route/daily/list'], resolve),
            meta: {title: '日常路线', power: 'admin.route.daily.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'RouteDailyAdd',
            component: resolve => require(['@/views/route/daily/modify'], resolve),
            meta: {title: '添加路线', power: 'admin.route.daily.add'},
            hidden: true
          }, {
            path: 'details',
            name: 'RouteDailyDetails',
            component: resolve => require(['@/views/route/daily/details'], resolve),
            meta: {title: '路线详情', power: 'admin.route.daily.details'},
            hidden: true
          }, {
            path: 'edit',
            name: 'RouteDailyEdit',
            component: resolve => require(['@/views/route/daily/modify'], resolve),
            meta: {title: '编辑路线', power: 'admin.route.daily.edit'},
            hidden: true
          }, {
            path: 'remarks',
            name: 'RouteDailyRemarks',
            component: resolve => require(['@/views/route/remarks'], resolve),
            meta: {title: '路线设置', power: 'admin.route.daily.remarks'},
            hidden: true
          }]
      },
      {
        path: 'fixed',
        name: 'RouteFixed',
        redirect: '/route/fixed/list',
        component: LayoutColumn,
        meta: {title: '包车路线', icon: '包车路线', power: 'admin.route.fixed'},
        children: [
          {
            path: 'list',
            name: 'RouteFixedList',
            component: resolve => require(['@/views/route/fixed/list'], resolve),
            meta: {title: '包车路线', power: 'admin.route.fixed.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'RouteFixedAdd',
            component: resolve => require(['@/views/route/fixed/modify'], resolve),
            meta: {title: '添加路线', power: 'admin.route.fixed.add'},
            hidden: true
          }, {
            path: 'details',
            name: 'RouteFixedDetails',
            component: resolve => require(['@/views/route/fixed/details'], resolve),
            meta: {title: '路线详情', power: 'admin.route.fixed.details'},
            hidden: true
          }, {
            path: 'edit',
            name: 'RouteFixedEdit',
            component: resolve => require(['@/views/route/fixed/modify'], resolve),
            meta: {title: '编辑路线', power: 'admin.route.fixed.edit'},
            hidden: true
          }, {
            path: 'remarks',
            name: 'RouteFixedRemarks',
            component: resolve => require(['@/views/route/remarks'], resolve),
            meta: {title: '路线设置', power: 'admin.route.fixed.remarks'},
            hidden: true
          }]
      },
      {
        path: 'airport',
        name: 'RouteAirport',
        redirect: '/route/airport/list',
        component: LayoutColumn,
        meta: {title: '机场接送', icon: '机场接送', power: 'admin.route.airport'},
        children: [
          {
            path: 'list',
            name: 'RouteAirportList',
            component: resolve => require(['@/views/route/airport/list'], resolve),
            meta: {title: '路线管理', power: 'admin.route.airport.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'RouteAirportAdd',
            component: resolve => require(['@/views/route/airport/modify'], resolve),
            meta: {title: '添加路线', power: 'admin.route.airport.add'},
            hidden: true
          }, {
            path: 'details',
            name: 'RouteAirportDetails',
            component: resolve => require(['@/views/route/airport/details'], resolve),
            meta: {title: '路线详情', power: 'admin.route.airport.details'},
            hidden: true
          }, {
            path: 'edit',
            name: 'RouteAirportEdit',
            component: resolve => require(['@/views/route/airport/modify'], resolve),
            meta: {title: '编辑路线', power: 'admin.route.airport.edit'},
            hidden: true
          }, {
            path: 'remarks',
            name: 'RouteAirportRemarks',
            component: resolve => require(['@/views/route/remarks'], resolve),
            meta: {title: '路线设置', power: 'admin.route.airport.remarks'},
            hidden: true
          }]
      }, {
        path: 'special',
        name: 'RouteSpecial',
        redirect: '/route/special/list',
        component: LayoutColumn,
        meta: {title: '专车接送', icon: '专车接送', power: 'admin.route.special'},
        children: [
          {
            path: 'list',
            name: 'RouteSpecialList',
            component: resolve => require(['@/views/route/special/list'], resolve),
            meta: {title: '路线管理', power: 'admin.route.special.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'RouteSpecialAdd',
            component: resolve => require(['@/views/route/special/modify'], resolve),
            meta: {title: '添加路线', power: 'admin.route.special.add'},
            hidden: true
          }, {
            path: 'details',
            name: 'RouteSpecialDetails',
            component: resolve => require(['@/views/route/special/details'], resolve),
            meta: {title: '路线详情', power: 'admin.route.special.details'},
            hidden: true
          }, {
            path: 'edit',
            name: 'RouteSpecialEdit',
            component: resolve => require(['@/views/route/special/modify'], resolve),
            meta: {title: '编辑路线', power: 'admin.route.special.edit'},
            hidden: true
          }, {
            path: 'remarks',
            name: 'RouteSpecialRemarks',
            component: resolve => require(['@/views/route/remarks'], resolve),
            meta: {title: '路线设置', power: 'admin.route.special.remarks'},
            hidden: true
          }]
      }
      // , {
      //   path: 'carpool',
      //   name: 'RouteCarpool',
      //   redirect: '/route/carpool/list',
      //   component: LayoutColumn,
      //   meta: {title: '跨境拼车', icon: 'table', power: 'admin.route.carpool'},
      //   children: [
      //     {
      //       path: 'list',
      //       name: 'RouteCarpoolList',
      //       component: resolve => require(['@/views/route/carpool/list'], resolve),
      //       meta: {title: '路线管理', power: 'admin.route.carpool.list'},
      //       hidden: true
      //     }, {
      //       path: 'add',
      //       name: 'RouteCarpoolAdd',
      //       component: resolve => require(['@/views/route/carpool/modify'], resolve),
      //       meta: {title: '添加路线', power: 'admin.route.carpool.add'},
      //       hidden: true
      //     }, {
      //       path: 'details',
      //       name: 'RouteCarpoolDetails',
      //       component: resolve => require(['@/views/route/carpool/details'], resolve),
      //       meta: {title: '路线详情', power: 'admin.route.carpool.details'},
      //       hidden: true
      //     }, {
      //       path: 'edit',
      //       name: 'RouteCarpoolEdit',
      //       component: resolve => require(['@/views/route/carpool/modify'], resolve),
      //       meta: {title: '编辑路线', power: 'admin.route.carpool.edit'},
      //       hidden: true
      //     }, {
      //       path: 'remarks',
      //       name: 'RouteCarpoolRemarks',
      //       component: resolve => require(['@/views/route/remarks'], resolve),
      //       meta: {title: '备注', power: 'admin.route.carpool.remarks'},
      //       hidden: true
      //     }]
      // }
    ],
    noCache: false
  },

  {
    path: '/rentCar',
    component: Layout,
    redirect: '/rentCar/branch',
    name: 'RentCar',
    meta: {title: '租车管理', icon: '租车管理', power: 'rentCar.index'},
    children: [
      {
        path: 'branch',
        name: 'RentCarBranch',
        redirect: '/rentCar/branch/list',
        component: LayoutColumn,
        meta: {title: '网点管理', icon: '网点管理', power: 'admin.rentCar.branch'},
        children: [
          {
            path: 'list',
            name: 'BranchList',
            component: resolve => require(['@/views/rentCar/branch/list'], resolve),
            meta: {title: '网点管理', power: 'admin.rentCar.branch.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'BranchAdd',
            component: resolve => require(['@/views/rentCar/branch/modify'], resolve),
            meta: {title: '添加网点', power: 'admin.rentCar.branch.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'BranchEdit',
            component: resolve => require(['@/views/rentCar/branch/modify'], resolve),
            meta: {title: '编辑网点', power: 'admin.rentCar.branch.edit'},
            hidden: true
          }, {
            path: 'car',
            name: 'BranchCar',
            component: resolve => require(['@/views/rentCar/branch/car'], resolve),
            meta: {title: '车型管理', power: 'admin.rentCar.branch.car'},
            hidden: true
          }]
      },
      {
        path: 'surcharge',
        name: 'RentCarSurcharge',
        component: resolve => require(['@/views/rentCar/surcharge'], resolve),
        meta: {title: '附加费用', icon: '附加费用', power: 'admin.rentCar.surcharge'}
      },
      {
        path: 'agreement',
        name: 'RentCarAgreement',
        redirect: '/rentCar/agreement/list',
        component: LayoutColumn,
        meta: {title: '协议管理', icon: '协议管理', power: 'admin.rentCar.agreement'},
        children: [
          {
            path: 'list',
            name: 'AgreementList',
            component: resolve => require(['@/views/rentCar/agreement/list'], resolve),
            meta: {title: '协议管理', power: 'admin.rentCar.agreement.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'AgreementAdd',
            component: resolve => require(['@/views/rentCar/agreement/modify'], resolve),
            meta: {title: '添加协议', power: 'admin.rentCar.agreement.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'AgreementEdit',
            component: resolve => require(['@/views/rentCar/agreement/modify'], resolve),
            meta: {title: '编辑协议', power: 'admin.rentCar.agreement.edit'},
            hidden: true
          }]
      }
    ],
    noCache: false
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    name: 'User',
    meta: {title: '用户管理', icon: '用户管理', power: 'admin.user'},
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'UserList',
        component: resolve => require(['@/views/user/list'], resolve),
        meta: {title: '用户列表', icon: '用户列表', power: 'admin.user.list'}
      }, {
        path: 'details',
        name: 'UserDetails',
        component: resolve => require(['@/views/user/details'], resolve),
        meta: {title: '用户信息', power: 'admin.user.details'},
        hidden: true
      }, {
        path: 'add',
        name: 'UserAdd',
        component: resolve => require(['@/views/user/add'], resolve),
        meta: {title: '添加用户', power: 'admin.user.add'},
        hidden: true
      }, {
        path: 'edit',
        name: 'UserEdit',
        component: resolve => require(['@/views/user/edit'], resolve),
        meta: {title: '编辑用户', power: 'admin.user.edit'},
        hidden: true
      }
    ],
    noCache: false
  },

  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    name: 'Order',
    meta: {title: '订单管理', icon: '订单管理', power: 'admin.order'},
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'OrderList',
        component: resolve => require(['@/views/order/list'], resolve),
        meta: {title: '订单列表', icon: '订单列表', power: 'admin.order.list'}
      }, {
        path: 'details',
        name: 'OrderDetails',
        component: resolve => require(['@/views/order/details'], resolve),
        meta: {title: '订单详情', power: 'admin.order.details'},
        hidden: true
      }, {
        path: 'setting',
        name: 'OrderSetting',
        component: resolve => require(['@/views/order/config/index'], resolve),
        meta: {title: '订单设置', icon: '订单设置', power: 'admin.order.setting'}
      }
    ],
    noCache: false
  },

  {
    path: '/financial',
    component: Layout,
    redirect: '/financial/apply',
    name: 'Financial',
    meta: {title: '提现管理', icon: '提现管理', power: 'admin.financial'},
    alwaysShow: true,
    children: [
      {
        path: 'apply',
        name: 'FinancialApplyList',
        component: resolve => require(['@/views/financial/apply'], resolve),
        meta: {title: '申请列表', icon: '申请列表', power: 'admin.financial.apply'}
      }, {
        path: 'rule',
        name: 'FinancialRule',
        component: resolve => require(['@/views/financial/rule'], resolve),
        meta: {title: '提现规则', icon: '提现规则', power: 'admin.financial.rule'}
      }
    ],
    noCache: false
  },

  {
    path: '/coupon',
    component: Layout,
    redirect: '/coupon/list',
    name: 'Coupon',
    meta: {title: '优惠券管理', icon: '优惠券管理', power: 'admin.coupon'},
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'CouponList',
        component: resolve => require(['@/views/coupon/list'], resolve),
        meta: {title: '优惠券列表', icon: '优惠券列表', power: 'admin.coupon.list'}
      }, {
        path: 'create',
        name: 'CouponCreate',
        component: resolve => require(['@/views/coupon/create'], resolve),
        meta: {title: '创建优惠券', power: 'admin.coupon.create'},
        hidden: true
      }, {
        path: 'edit',
        name: 'CouponEdit',
        component: resolve => require(['@/views/coupon/edit'], resolve),
        meta: {title: '编辑优惠券', power: 'admin.coupon.edit'},
        hidden: true
      }
    ],
    noCache: false
  },

  {
    path: '/invoice',
    component: Layout,
    redirect: '/invoice/list',
    name: 'Invoice',
    meta: {title: '发票管理', icon: '发票管理', power: 'admin.invoice'},
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'InvoiceList',
        component: resolve => require(['@/views/invoice/list'], resolve),
        meta: {title: '申请列表', icon: '申请列表', power: 'admin.invoice.list'}
      }, {
        path: 'details',
        name: 'InvoiceDetails',
        component: resolve => require(['@/views/invoice/details'], resolve),
        meta: {title: '开票详情', power: 'admin.invoice.details'},
        hidden: true
      }
    ],
    noCache: false
  },

  {
    path: '/customerService',
    component: Layout,
    redirect: '/customerService/telephone',
    name: 'CustomerService',
    meta: {title: '客服中心', icon: '客服中心', power: 'admin.customerService'},
    children: [
      {
        path: 'telephone',
        name: 'CustomerServiceTelephone',
        component: resolve => require(['@/views/customerService/telephone'], resolve),
        meta: {title: '联系电话', icon: '联系电话', power: 'admin.customerService.telephone'}
      }, {
        path: 'instructions',
        name: 'Instructions',
        redirect: '/customerService/instructions/parentList',
        component: LayoutColumn,
        meta: {title: '文章栏目', icon: '文章栏目', power: 'admin.customerService.instructions'},
        children: [
          {
            path: 'parentList',
            name: 'InstructionsParentList',
            component: resolve => require(['@/views/customerService/instructions/parentList/list'], resolve),
            meta: {title: '栏目列表', power: 'admin.customerService.parentList'},
            hidden: true
          }, {
            path: 'parentListAdd',
            name: 'InstructionsParentListAdd',
            component: resolve => require(['@/views/customerService/instructions/parentList/add'], resolve),
            meta: {title: '新增栏目', power: 'admin.customerService.parentListAdd'},
            hidden: true
          }, {
            path: 'parentListEdit',
            name: 'InstructionsParentListEdit',
            component: resolve => require(['@/views/customerService/instructions/parentList/edit'], resolve),
            meta: {title: '编辑栏目', power: 'admin.customerService.parentListEdit'},
            hidden: true
          }, {
            path: 'sublist',
            name: 'InstructionsSublist',
            component: resolve => require(['@/views/customerService/instructions/sublist/list'], resolve),
            meta: {title: '文章列表', power: 'admin.customerService.sublist'},
            hidden: true
          }, {
            path: 'sublistAdd',
            name: 'InstructionsSublistAdd',
            component: resolve => require(['@/views/customerService/instructions/sublist/add'], resolve),
            meta: {title: '添加文章', power: 'admin.customerService.sublistAdd'},
            hidden: true
          }, {
            path: 'sublistEdit',
            name: 'InstructionsSublistEdit',
            component: resolve => require(['@/views/customerService/instructions/sublist/edit'], resolve),
            meta: {title: '编辑文章', power: 'admin.customerService.sublistEdit'},
            hidden: true
          }, {
            path: 'sublistDetails',
            name: 'InstructionsSublistDetails',
            component: resolve => require(['@/views/customerService/instructions/sublist/details'], resolve),
            meta: {title: '文章详情', power: 'admin.customerService.sublistDetails'},
            hidden: true
          }]
      }
    ],
    noCache: false
  },

  {
    path: '/wxApp',
    component: Layout,
    redirect: '/wxApp/agentWxApp',
    name: 'WxApp',
    meta: {title: '小程序管理', icon: '小程序管理', power: 'setting'},
    alwaysShow: true,
    children: [
      {
        path: 'publishWxApp',
        name: '发布小程序',
        component: resolve => require(['@/views/wxapp/publish'], resolve),
        meta: {title: '发布小程序', icon: '发布小程序', power: 'setting.publishWxApp'}
      }
    ],
    noCache: false
  },

  {
    path: '/config',
    component: Layout,
    redirect: '/config/wxapp',
    name: 'Config',
    meta: {title: '系统设置', icon: '系统设置', power: 'admin.config'},
    children: [
      {
        path: 'index',
        name: 'BaseConfig',
        component: resolve => require(['@/views/config/config'], resolve),
        meta: {title: '基本配置', icon: '基本配置', power: 'admin.config.system'}
      },
      {
        //   path: 'notice',
        //   name: 'NoticeConfig',
        //   component: resolve => require(['@/views/config/notice'], resolve),
        //   meta: {title: '推送配置', icon: 'table', power: 'admin.config.notice'}
        // }, {
        path: 'aboutUs',
        name: 'AboutUs',
        component: resolve => require(['@/views/config/aboutUs'], resolve),
        meta: {title: '关于我们', icon: '关于我们', power: 'admin.config.aboutUs'}
      }
    ],
    noCache: false
  },

  {
    path: '/preset',
    component: Layout,
    redirect: '/preset/airport',
    name: 'Preset',
    meta: {title: '预设管理', icon: '预设管理', power: 'admin.preset'},
    children: [
      {
        path: 'airport',
        name: 'Airport',
        redirect: '/preset/airport/list',
        component: LayoutColumn,
        meta: {title: '机场管理', icon: '机场管理', power: 'admin.preset.airport'},
        children: [
          {
            path: 'list',
            name: 'PresetAirportList',
            component: resolve => require(['@/views/preset/airport/list'], resolve),
            meta: {title: '机场列表', power: 'admin.preset.airport.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'PresetAirportAdd',
            component: resolve => require(['@/views/preset/airport/add'], resolve),
            meta: {title: '添加机场', power: 'admin.preset.airport.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'PresetAirportEdit',
            component: resolve => require(['@/views/preset/airport/edit'], resolve),
            meta: {title: '编辑机场', power: 'admin.preset.airport.edit'},
            hidden: true
          }]
      }, {
        path: 'car',
        name: 'Car',
        redirect: '/preset/car/type',
        component: LayoutColumn,
        meta: {title: '车辆管理', icon: '车辆管理', power: 'admin.preset.car'},
        children: [
          {
            path: 'type',
            name: 'PresetCarType',
            component: resolve => require(['@/views/preset/car/type'], resolve),
            meta: {title: '车辆类型', power: 'admin.preset.car.type'},
            hidden: true
          }, {
            path: 'addType',
            name: 'PresetAddCarType',
            component: resolve => require(['@/views/preset/car/addType'], resolve),
            meta: {title: '添加车辆类型', power: 'admin.preset.car.addType'},
            hidden: true
          }, {
            path: 'editType',
            name: 'PresetEditCarType',
            component: resolve => require(['@/views/preset/car/editType'], resolve),
            meta: {title: '编辑车辆类型', power: 'admin.preset.car.editType'},
            hidden: true
          }, {
            path: 'list',
            name: 'PresetCarList',
            component: resolve => require(['@/views/preset/car/list'], resolve),
            meta: {title: '车辆列表', power: 'admin.preset.car.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'PresetCarAdd',
            component: resolve => require(['@/views/preset/car/add'], resolve),
            meta: {title: '添加车辆', power: 'admin.preset.car.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'PresetCarEdit',
            component: resolve => require(['@/views/preset/car/edit'], resolve),
            meta: {title: '编辑车辆', power: 'admin.preset.car.edit'},
            hidden: true
          }]
      }, {
        path: 'driver',
        name: 'Driver',
        redirect: '/preset/driver/list',
        component: LayoutColumn,
        meta: {title: '司机管理', icon: '司机管理', power: 'admin.preset.driver'},
        children: [
          {
            path: 'list',
            name: 'PresetDriverList',
            component: resolve => require(['@/views/preset/driver/list'], resolve),
            meta: {title: '司机列表', power: 'admin.preset.driver.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'PresetDriverAdd',
            component: resolve => require(['@/views/preset/driver/add'], resolve),
            meta: {title: '添加司机', power: 'admin.preset.driver.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'PresetDriverEdit',
            component: resolve => require(['@/views/preset/driver/edit'], resolve),
            meta: {title: '编辑司机', power: 'admin.preset.driver.edit'},
            hidden: true
          }]
      }, {
        path: 'verifier',
        name: 'Verifier',
        redirect: '/preset/verifier/list',
        component: LayoutColumn,
        meta: {title: '核销员管理', icon: '核销员管理', power: 'admin.preset.verifier'},
        children: [
          {
            path: 'list',
            name: 'PresetVerifierList',
            component: resolve => require(['@/views/preset/verifier/list'], resolve),
            meta: {title: '核销员列表', power: 'admin.preset.verifier.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'PresetVerifierAdd',
            component: resolve => require(['@/views/preset/verifier/add'], resolve),
            meta: {title: '添加核销员', power: 'admin.preset.verifier.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'PresetVerifierEdit',
            component: resolve => require(['@/views/preset/verifier/edit'], resolve),
            meta: {title: '编辑核销员', power: 'admin.preset.verifier.edit'},
            hidden: true
          }]
      }, {
        path: 'reason',
        name: 'Reason',
        redirect: '/preset/reason/list',
        component: LayoutColumn,
        meta: {title: '原因管理', icon: '原因管理', power: 'admin.preset.reason'},
        children: [
          {
            path: 'list',
            name: 'PresetReasonList',
            component: resolve => require(['@/views/preset/reason/list'], resolve),
            meta: {title: '原因列表', power: 'admin.preset.reason.list'},
            hidden: true
          }, {
            path: 'add',
            name: 'PresetReasonAdd',
            component: resolve => require(['@/views/preset/reason/add'], resolve),
            meta: {title: '添加原因', power: 'admin.preset.reason.add'},
            hidden: true
          }, {
            path: 'edit',
            name: 'PresetReasonEdit',
            component: resolve => require(['@/views/preset/reason/edit'], resolve),
            meta: {title: '编辑原因', power: 'admin.preset.reason.edit'},
            hidden: true
          }]
      }, {
        path: 'appShare',
        name: 'AppShare',
        component: resolve => require(['@/views/preset/share/index'], resolve),
        meta: {title: '分享管理', icon: '分享管理', power: 'admin.preset.share.index'}
      }
    ],
    noCache: false
  },

  {path: '/debug', component: resolve => require(['@/views/_debug/index'], resolve), hidden: true},

  {path: '*', redirect: '/404', hidden: true}
];

const router = new Router({
  // mode: 'history', //后端支持可开
  'scrollBehavior': () => ({y: 0}),
  routes: constantRouterMap
});

import {getUrlPramas} from '@/utils/index';
import {$config} from 'vue-element-simple';
import {setToken, setSaaSId, getToken} from '../utils/auth';
import store from '../store';

router.beforeEach((to, from, next) => {
  NProgress.start();
  // 判断是否是SaaS登录
  if (window.location.href.indexOf('system=') >= 0) {
    const SaaSId = getUrlPramas('system');
    console.log('========SaaS登录=========');
    console.log('SaaSId: ' + SaaSId);
    setSaaSId(SaaSId);
  }

  // 当前界面不为登录界面，则加载用户信息
  if (to.path !== '/login') {
    // 判断是否是自动登录
    if (window.location.href.indexOf('wsToken=') >= 0) {
      const wsToken = getUrlPramas('wsToken');
      const wsDomain = getUrlPramas('wsDomain');
      console.log('========自动登录=========');
      console.log('wsToken: ' + wsToken);
      console.log('wsDomain: ' + wsDomain);
      (async () => {
        // 自动登录换取token
        const result = await Service.adminAutoLogin({wsToken: wsToken, wsDomain: wsDomain});
        if (result.code === 0) {
          console.log('换回token: ' + result.data.token);
        }
        // 界面跳转时，获取角色信息
        (async () => await Service.adminRoleGetAdminInfo())();
        // next();
        location.replace($config['API_PATH'] + '/');
      })();
    } else if (window.location.href.indexOf('SaaSToken=') >= 0) {
      // SaaS跳转时
      const SaaSToken = getUrlPramas('SaaSToken');
      const SaaSId = getUrlPramas('SaaSId');
      console.log('========SaaS登录=========');
      console.log('SaaSToken: ' + SaaSToken);
      console.log('SaaSId: ' + SaaSId);
      (async () => {
        await setToken(SaaSToken);
        await setSaaSId(SaaSId);
        await store.commit('SET_TOKEN', SaaSToken);
        // 界面跳转时，获取角色信息
        await Service.adminRoleGetAdminInfo();
        // location.replace('http://192.168.10.116:9529/');
        location.replace($config['API_PATH'] + '/');
      })();
    } else if (getToken()) {
      // 界面跳转时，获取角色信息
      (async () => {
        await Service.adminRoleGetAdminInfo();
        next();
      })();
    } else {
      next('/login');
    }
  } else {
    next();
  }
});

router.afterEach(() => {
  NProgress.done() // 结束Progress
});

export default router;
